<?php

namespace handle\message;

use handle\message\lib\Entrance;
use handle\message\log\CustomException;
use Workerman\Connection\TcpConnection;

class Index
{
    public static function handle(TcpConnection $connection, $data)
    {
        $error = self::startRecordError();
//        echo "客户端发送数据：{$data}\r\n";
//        $connection->send("已收到：{$data}");
        workerMessage('接收到的数据:' . $data);
        $game = Entrance::getInstance();
        $game->setConnection($connection);
        $game->validateData($data);
        $game->startupMethod();

//        echo '------------------------------------------------------' . PHP_EOL;
//        self::printCallStack();
//        echo '------------------------------------------------------' . PHP_EOL;
    }

    /**
     * 开始记录错误信息
     * @return CustomException
     */
    private static function startRecordError(): CustomException
    {
        return CustomException::getInstance();
    }

}